import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { ActivatedRoute } from '@angular/router';
import { parts } from '../HuoMesstmp.model';


@Component({
  selector: 'app-MessCusAdmin',
  templateUrl: './MessCusAdmin.component.html',
  styleUrls: ['./MessCusAdmin.component.scss']
})
export class MessCusAdminComponent implements OnInit {
  _displayData = [];
  public data = [];
  public _total = 0;
  public pageIndex = 1;
  public parts: parts = new parts();
  public cusInfo:any = [];
  public showCheck: boolean = false;

  constructor(
    public apiService: ApiService,
    private route: ActivatedRoute
  ) { }

  ngOnInit() {
    this.getId();
  }

    getId(){
     this.route.params.subscribe((params) => {
            this.load(params['id']);
            if(params['sec'] == 'sec' ){
              this.showCheck = true;
              this.loadSec(params['id']);
            }// 通过这个方法来判断是否为部门查看
        });
  }

  load(id){
    let url = "findbigcustomerdetail"
    this.apiService.get(url,{"bigCustomerId":id})
      .then(res =>{
        console.log(res);
        this.cusInfo = res.result;
      })
  }
  
  loadSec(id){
    let url = "findbigcustomersdepartmentinfo"
    this.parts.bigCustomerId = id;
    this.apiService.get(url,this.parts)
      .then(res =>{
        console.log(res);
        this.data = res.result;
        this._total = res.totalCount;
      })
  }

  loadSecd(){
    let url = "findbigcustomersdepartmentinfo"
    this.apiService.get(url,this.parts)
      .then(res =>{
        console.log(res);
        this.data = res.result;
        this._total = res.totalCount;
      })
  }

  resetIndex(e) {
        console.log(e);
        this.parts.setPage(e);
        this.loadSecd();
  }



}
